// 乘法快速幂模版
// 求a的b次方，对p取模的结果
// 测试链接 : https://www.luogu.com.cn/problem/P1226
// 提交以下的code，可以直接通过

#include <bits/stdc++.h>

using namespace std;

#define ll long long
ll a, b, p;

inline ll read()
{
    char ch = getchar();
    ll x = 0, f = 1;
    while(ch < '0' || ch > '9')
    {
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        x = 10 * x + ch - '0';
        ch = getchar();
    }
    return f * x;
}

ll power(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1) ans = ans * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return ans;
}

int main()
{
    a = read();
    b = read();
    p = read();
    printf("%lld^%lld mod %lld=%lld\n", a, b, p, power(a, b));

    return 0;
}